home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / addsub.c < prev    next >
C/C++ Source or Header  |  1993-06-25  |  4KB  |  144 lines

  1.  
  2.  
  3.    /***********************************************
  4.    *
  5.    *       file d:\cips\addsub.c
  6.    *
  7.    *       Functions: This file contains
  8.    *          add_image_array
  9.    *          subtract_image_array
  10.    *
  11.    *       Purpose:
  12.    *          These functions implement
  13.    *          image addition and subtraction.
  14.    *
  15.    *       External Calls:
  16.    *          wtiff.c - round_off_image_size
  17.    *                    create_file_if_needed
  18.    *                    write_array_into_tiff_image
  19.    *          tiff.c - read_tiff_header
  20.    *          rtiff.c - read_tiff_image
  21.    *
  22.    *
  23.    *       Modifications:
  24.    *          1 April 1992 - created
  25.    *
  26.    *************************************************/
  27.  
  28. #include "cips.h"
  29.  
  30.      /*******************************************
  31.      *
  32.      *   add_image_array(...
  33.      *
  34.      *   This function adds two ROWSxCOLS image
  35.      *   sections.  The image file named out_name
  36.      *   will receive the sum of the image file
  37.      *   named in1_name and the image file
  38.      *   named in2_name.
  39.      *
  40.      *******************************************/
  41.  
  42.  
  43. add_image_array(in1_name, in2_name, out_name, 
  44.                 the_image, out_image,
  45.           il1, ie1, ll1, le1,
  46.           il2, ie2, ll2, le2,
  47.           il3, ie3, ll3, le3)
  48.    char   in1_name[], in2_name[], out_name[];
  49.    int    il1, ie1, ll1, le1,
  50.           il2, ie2, ll2, le2,
  51.           il3, ie3, ll3, le3;
  52.    short  the_image[ROWS][COLS],
  53.           out_image[ROWS][COLS];
  54.  
  55. {
  56.    int    i, j, length, max, width;
  57.    struct tiff_header_struct image_header;
  58.  
  59.    create_file_if_needed(in1_name, out_name, out_image);
  60.  
  61.    read_tiff_header(in1_name, &image_header);
  62.  
  63.    max = 255;
  64.    if(image_header.bits_per_pixel == 4)
  65.       max = 16;
  66.  
  67.    read_tiff_image(in1_name, the_image, 
  68.                    il1, ie1, ll1, le1);
  69.    read_tiff_image(in2_name, out_image, 
  70.                    il2, ie2, ll2, le2);
  71.  
  72.    for(i=0; i<ROWS; i++){
  73.       for(j=0; j<COLS; j++){
  74.          out_image[i][j] = the_image[i][j] + 
  75.                            out_image[i][j];
  76.          if(out_image[i][j] > max)
  77.             out_image[i][j] = max;
  78.       }  /* ends loop over j */
  79.    }  /* ends loop over i */
  80.  
  81.    write_array_into_tiff_image(out_name, out_image,
  82.                                il3, ie3, ll3, le3);
  83.  
  84. }  /* ends add_image_array */
  85.  
  86.  
  87.  
  88.  
  89.  
  90.      /*******************************************
  91.      *
  92.      *   subtract_image_array(...
  93.      *
  94.      *   This function subtracts two ROWSxCOLS image
  95.      *   sections.  The image file named out_name
  96.      *   will receive the difference of the image file
  97.      *   named in1_name and the image file
  98.      *   named in2_name.
  99.      *
  100.      *   out_name = in1_name - in2_name
  101.      *
  102.      *******************************************/
  103.  
  104.  
  105. subtract_image_array(in1_name, in2_name, out_name, 
  106.                      the_image, out_image,
  107.           il1, ie1, ll1, le1,
  108.           il2, ie2, ll2, le2,
  109.           il3, ie3, ll3, le3)
  110.    char   in1_name[], in2_name[], out_name[];
  111.    int    il1, ie1, ll1, le1,
  112.           il2, ie2, ll2, le2,
  113.           il3, ie3, ll3, le3;
  114.    short  the_image[ROWS][COLS],
  115.           out_image[ROWS][COLS];
  116.  
  117. {
  118.    int    i, j, length, width;
  119.    struct tiff_header_struct image_header;
  120.  
  121.  
  122.    create_file_if_needed(in1_name, out_name, out_image);
  123.  
  124.    read_tiff_header(in1_name, &image_header);
  125.  
  126.    read_tiff_image(in1_name, the_image, 
  127.                    il1, ie1, ll1, le1);
  128.    read_tiff_image(in2_name, out_image, 
  129.                    il2, ie2, ll2, le2);
  130.  
  131.    for(i=0; i<ROWS; i++){
  132.       for(j=0; j<COLS; j++){
  133.          out_image[i][j] = the_image[i][j] - 
  134.                            out_image[i][j];
  135.          if(out_image[i][j] < 0)
  136.             out_image[i][j] = 0;
  137.       }  /* ends loop over j */
  138.    }  /* ends loop over i */
  139.  
  140.    write_array_into_tiff_image(out_name, out_image,
  141.                                il3, ie3, ll3, le3);
  142.  
  143. }  /* ends subtract_image_array */
  144.